from Api_A3mall.utils.read import *
from Api_A3mall.utils.mysql import *
from Api_A3mall.config.contest import *
import pytest

@pytest.fixture(scope="module")
def sql():
    sql = A3mall_db(
        host='10.59.9.12',
        user='root',
        pwd='yidong666',
        database='a3mall'
    )
    yield sql
    sql.close()

@pytest.fixture(scope='module')
def api():
    return lianjie(base_url='http://10.59.9.12:7001')

@pytest.mark.parametrize('username,password,exp',read_excel())
def test_A3mall_login(sql, api, username,password,exp):
    data = {
        'username':username,
        'password':password
    }
    response = api.post('/api/public/login', data=data)
    print(response.json())
    assert response.json()['info'] == exp
    try:
        dy1 = sql.select("select username from mall_users where username = '{data['username']}'")
        assert dy1[0][0] == data['username'],'用户名与数据库不匹配'
    except Exception as q:
        print(q)

if __name__ == '__main__':
    pytest.main(['-s'])